<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>popot-2.01: example-001.cc</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">popot-2.01
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">example-001.cc</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">// In this example, we show a basic usage of the SPSO algorithms, using the default ones</span>
<span class="comment">// provided by the library</span>

<span class="comment">// We first define the generator of random numbers</span>
<span class="comment">// THIS is absolutely necessary to define RNG_GENERATOR before</span>
<span class="comment">// including popot.h as some of the codes require it to be defined</span>
<span class="preprocessor">#include &quot;<a class="code" href="rng__generators_8h.html">rng_generators.h</a>&quot;</span>
<span class="keyword">typedef</span> popot::rng::CRNG RNG_GENERATOR;

<span class="comment">// And then include our headers (these make use of the RNG_GENERATOR, so we must include </span>
<span class="comment">// them after the definition of RNG_GENERATOR</span>
<span class="preprocessor">#include &quot;<a class="code" href="popot_8h.html">popot.h</a>&quot;</span>

<span class="comment">// Define the vector type and the problem</span>
<span class="keyword">typedef</span> popot::algorithm::ParticleSPSO::VECTOR_TYPE TVector;
<span class="keyword">typedef</span> popot::problems::Rosenbrock Problem;

<span class="comment">// **************************************** //</span>
<span class="comment">// ************** Main ******************** //</span>
<span class="comment">// **************************************** //</span>

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]) {

  RNG_GENERATOR::rng_srand();
  RNG_GENERATOR::rng_warm_up();
  
  <span class="comment">// Some initialization of static fields</span>
  <span class="keywordtype">size_t</span> dimension = 50;
  Problem p(50);
  
  <span class="comment">// Let&#39;s create a swarm </span>
  <span class="comment">// we might use spso2006, spso2007 or spso2011</span>
  <span class="keyword">auto</span> algo = <a name="a0"></a><a class="code" href="namespacepopot_1_1algorithm.html#aafd0464056160a6c9e1cf33409e053f0">popot::algorithm::spso2011</a>(dimension,
                                         [&amp;p] (<span class="keywordtype">size_t</span> index) -&gt; <span class="keywordtype">double</span> { <span class="keywordflow">return</span> p.get_lbound(index); },
                                         [&amp;p] (<span class="keywordtype">size_t</span> index) -&gt; <span class="keywordtype">double</span> { <span class="keywordflow">return</span> p.get_ubound(index); },
                                         [&amp;p] (<span class="keywordtype">double</span> fitness, <span class="keywordtype">int</span> epoch) -&gt; <span class="keywordtype">bool</span> { <span class="keywordflow">return</span> p.stop(fitness, epoch);},
                                         [&amp;p] (TVector &amp;pos) -&gt; <span class="keywordtype">double</span> { <span class="keywordflow">return</span> p.evaluate(pos.getValuesPtr());}
                                         );


  <span class="comment">// We now run our algorithm</span>
  algo.run(1);

  std::cout &lt;&lt; <span class="stringliteral">&quot;Nb steps : &quot;</span> &lt;&lt; algo.epoch &lt;&lt; <span class="stringliteral">&quot; ; # of generated neighborhoods : &quot;</span> &lt;&lt; algo.nb_new_neigh &lt;&lt; std::endl;

}
</pre></div> </div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5
</small></address>

</body>
</html>
